package telbook;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class DeleteServlet
 */
public class DeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setHeader("content-type","text/html;charset=UTF-8");
		response.setContentType("UTF-8");
		String number=request.getParameter("name");
		String table=request.getParameter("table");
		Connection conn=null;
		Statement stmt=null;
		try {
//			获取数据连接
			conn=JDBCUtils.getConnection();
//			获取Statement对象
			stmt=conn.createStatement();
//			发送SQL语句
			String sql="delete from "+table+" where number='"+number+"'";
			stmt.execute(sql);
			request.getRequestDispatcher("check.jsp").forward(request, response);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			JDBCUtils.release(stmt, conn);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
